package com.dhh.sky.activity;

import java.util.Timer;
import java.util.TimerTask;

import com.dhh.sky.R;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class ShowImageActivity extends Activity{
	private boolean isHideBar = false;
	private LinearLayout actionBarBottom;
	private ImageView img;
	private Timer timer;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.image_view); 
		actionBarBottom = (LinearLayout) this.findViewById(R.id.actionBarBottom);
		img = (ImageView) this.findViewById(R.id.imageView1);
		img.setOnClickListener(new View.OnClickListener() {			
			@Override
			public void onClick(View v) {
				hideBar(!isHideBar);
			}
		});
	}
	
	private void hideBar(boolean isHid){
		isHideBar = isHid;
		if(isHideBar){
			actionBarBottom.setVisibility(View.GONE);
			if(timer!=null){
				timer.cancel();
				timer.purge();
			}
		}else{
			actionBarBottom.setVisibility(View.VISIBLE);
			timer = new Timer();
			timer.schedule(new HideBarTask(), 5000);
		}
	}
	
	class HideBarTask extends TimerTask {
		@Override
		public void run() {
			Message msg = new Message();
			Bundle data = new Bundle();
			data.putBoolean("isHid", true);
			msg.setData(data);
			hidHandler.sendMessage(msg);
		}
	}
	
	private Handler hidHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {    
    		Bundle data = msg.getData();
    		boolean isHid = data.getBoolean("isHid");
    		hideBar(isHid);
        }
    };
}
